package com.kaka.bus.adapter;

import android.app.Activity;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.kaka.bus.R;
import com.kaka.bus.bean.ProductDetailBean;

import java.util.List;

public class InfoFinishRegistAdapter extends BaseQuickAdapter<ProductDetailBean, BaseViewHolder> {
    private Activity mActivity;
    private List<ProductDetailBean> beans;

    public InfoFinishRegistAdapter(Activity activity, int layoutResId, @Nullable List<ProductDetailBean> data) {
        super(layoutResId, data);
        mActivity = activity;
        beans = data;
    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return super.onCreateViewHolder(parent, viewType);
    }

    @Override
    public int getItemViewType(int position) {
        if (beans.get(position).getProductType() == -1) {
            isHeader(position);
        }
        return super.getItemViewType(position);
    }

    @Override
    protected void convert(BaseViewHolder helper, ProductDetailBean item) {
        if (item.getProductType() == -1) {
            helper.getView(R.id.img_mainpro).setVisibility(View.GONE);
            helper.getView(R.id.tv_mainprotitle).setVisibility(View.GONE);
            helper.getView(R.id.img_default).setVisibility(View.VISIBLE);
            helper.getView(R.id.tv_default).setVisibility(View.VISIBLE);
        } else {
            helper.getView(R.id.img_mainpro).setVisibility(View.VISIBLE);
            helper.getView(R.id.tv_mainprotitle).setVisibility(View.VISIBLE);
            helper.getView(R.id.img_default).setVisibility(View.GONE);
            helper.getView(R.id.tv_default).setVisibility(View.GONE);
            helper.setText(R.id.tv_mainprotitle, item.getProductName());
            ImageView imageView = helper.getView(R.id.img_mainpro);
            Glide.with(mActivity).load(item.getProductIcon()).into(imageView);
        }
    }

    public boolean isHeader(int position) {
        if(beans.get(position).getProductType()==-1) {
            return true;
        }else {
            return false;
        }
    }


}
